import request from '@/utils/request'

//从配置中获取业务的地址
import {baseUrlConfig} from '@/config/config'
const basePath = baseUrlConfig.userCenterUrl
const enterprisePath = baseUrlConfig.enterprise
const funcApiPath = baseUrlConfig.funcApi
const bastPath = baseUrlConfig.oneAccess1

// 用户登录
export const userLogin = (data: { flag?: string; password: string; userName: string }) => {
  return request({
    url: basePath + '/user/login',
    method: 'post',
    data
  })
}
// 用户登出
export const userLogout = (data: { token?: string; userId: number }) => {
  return request({
    url: basePath + '/user/logout',
    method: 'post',
    data
  })
}
// 菜单&功能权限
export const getFuncPermissions = (data: { userName: string; sysFlag: string }) => {
  return request({
    url: funcApiPath + '/user/function/permissions/find/system/checkedPermissions',
    method: 'post',
    data
  })
}

// 用户组织架构（所属部门）
export const getOrgInfo = ( id: string ) => {
  return request({
    url: enterprisePath + '/enterprise/department/get',
    method: 'get',
    params: { id }
  })
}

// 用户组织架构树
export const getOrganTree = (data: { enterpriseIds: any; state: string,id: string }) => {
  return request({
    url: enterprisePath + '/enterprise/department/findTree',
    method: 'post',
    data
  })
}

// 用户所属的系统下拉列表
export const getUserSystem = (userName: string) => {
  return request({
    url: funcApiPath + '/user/function/permissions/find/user/systems',
    method: 'get',
    params: { userName }
  })
}


// 通过第三方id免登
export const loginAndGetUser = (userName: string) => {
  return request({
    url: bastPath + '/user/login/no/password',
    method: 'POST',
    data: { userName }
  })
}